/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.util.ArrayList;
import org.newdawn.slick.Animation;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Polygon;
import physics.Physics;

/**
 *
 * @author wida52629504
 */
public abstract class GameCharacter implements Entity {

    private String name;
    private float jump;
    private int life;
    private int maxLife;
    private int exp;
    private float xRight;
    private float xLeft;
    private float yUp;
    private float yBottom;
    private float axRight;
    private float axLeft;
    private float ayUp;
    private float ayBottom;
    private float posX = 0;
    private float posY = 0;
    private float velX = 0;
    private float velY = 0;
    private float speed;
    private Polygon poly;
    private Polygon atackPoly;
    private ArrayList<Image> imgs;
    public Animation animation = new Animation();
    public Animation animationJumpL = new Animation();
    public Animation animationJumpR = new Animation();
    public Animation animationRR = new Animation();
    public Animation animationRL = new Animation();
    public Animation animationAtR = new Animation();
    public Animation animationAtL = new Animation();
    public Animation animationShtR = new Animation();
    public Animation animationShtL = new Animation();
    public Animation animationR = new Animation();
    public Animation animationL = new Animation();
    public Animation animationDownR = new Animation();
    public Animation animationDownL = new Animation();
    public Animation animationDownShtR = new Animation();
    public Animation animationDownShtL = new Animation();
    public Animation animationParedR = new Animation();
    public Animation animationParedL = new Animation();
    public Animation animationFastR = new Animation();
    public Animation animationFastL = new Animation();
    public Animation animationDieR = new Animation();
    public Animation animationDieL = new Animation();
    public Animation animationHurtR = new Animation();
    public Animation animationHurtL = new Animation();
    public int atackTime;
    public int shootTime;
    public int maxAtackTime;
    public int maxShootTime;
    public int hurtTime = 0;
    private int dieTime = 0;
    private boolean saltable;
    private boolean left;
    private boolean atack;
    private boolean shoot;
    private boolean down = false;
    private boolean pared = false;
    private boolean dead = false;
    private boolean hurt = false;
    private boolean dieAni = false;
    private int margenUp = 27;
    private int margenDown = 25;

    //constructor de prueva
//    public GameCharacter() {
//        try {
//            animation = new Animation();
//            animationR = new Animation();
//            animationR.setAutoUpdate(true);
//            animationL = new Animation();
//            animationL.setAutoUpdate(true);
//            animationJumpR = new Animation();
//            animationJumpL = new Animation();
//            animationRR = new Animation();
//            animationRL = new Animation();
//            animationAtR = new Animation();
//            animationAtL = new Animation();
//            animationShtR = new Animation();
//            animationShtL = new Animation();
//            for (int frame = 0; frame < 4; frame++) {
//                animationR.addFrame(new Image("resources/RoSta0" + (frame + 1) + ".png"), 200);
//                animationL.addFrame(new Image("resources/RoSta11.png"), 200);
//                animationJumpR.addFrame(new Image("resources/RoJum01.png"), 200);
//                animationJumpL.addFrame(new Image("resources/RoJum11.png"), 200);
//                animationRR.addFrame(new Image("resources/RoRun01.png"), 200);
//                animationRL.addFrame(new Image("resources/RoRun11.png"), 200);
//                animationAtR.addFrame(new Image("resources/RoFght01.png"), 200);
//                animationAtL.addFrame(new Image("resources/RoFght11.png"), 200);
//                animationShtR.addFrame(new Image("resources/RoShot01.png"), 200);
//                animationShtL.addFrame(new Image("resources/RoShot11.png"), 200);
//            }
//            animation = animationR;
//            left = true;
//            atack = false;
//            shoot = false;
//            atackTime = 0;
//            shootTime = 0;
//            setAtackPoly(45, 65, 27, 71);
//        } catch (SlickException e) {
//            System.out.println(e);
//        }
//    }
    public float getSpeed() {
        return speed;
    }

    public void setSpeed(float speed) {
        this.speed = speed;
    }

    public float getJump() {
        return jump;
    }

    public void setJump(float jump) {
        this.jump = jump;
    }

    public Animation getAnimationAtL() {
        return animationAtL;
    }

    public void setAnimationAtL(Animation animationAtL) {
        this.animationAtL = animationAtL;
    }

    public Animation getAnimationAtR() {
        return animationAtR;
    }

    public void setAnimationAtR(Animation animationAtR) {
        this.animationAtR = animationAtR;
    }

    public Animation getAnimationJumpL() {
        return animationJumpL;
    }

    public void setAnimationJumpL(Animation animationJumpL) {
        this.animationJumpL = animationJumpL;
    }

    public Animation getAnimationJumpR() {
        return animationJumpR;
    }

    public void setAnimationJumpR(Animation animationJumpR) {
        this.animationJumpR = animationJumpR;
    }

    public Animation getAnimationL() {
        return animationL;
    }

    public void setAnimationL(Animation animationL) {
        this.animationL = animationL;
    }

    public Animation getAnimationR() {
        return animationR;
    }

    public void setAnimationR(Animation animationR) {
        this.animationR = animationR;
    }

    public Animation getAnimationRL() {
        return animationRL;
    }

    public void setAnimationRL(Animation animationRL) {
        this.animationRL = animationRL;
    }

    public Animation getAnimationRR() {
        return animationRR;
    }

    public void setAnimationRR(Animation animationRR) {
        this.animationRR = animationRR;
    }

    public Animation getAnimationShtL() {
        return animationShtL;
    }

    public void setAnimationShtL(Animation animationShtL) {
        this.animationShtL = animationShtL;
    }

    public Animation getAnimationShtR() {
        return animationShtR;
    }

    public void setAnimationShtR(Animation animationShtR) {
        this.animationShtR = animationShtR;
    }

    public float getAxLeft() {
        return axLeft;
    }

    public void setAxLeft(float axLeft) {
        this.axLeft = axLeft;
    }

    public float getAxRight() {
        return axRight;
    }

    public void setAxRight(float axRight) {
        this.axRight = axRight;
    }

    public float getAyBottom() {
        return ayBottom;
    }

    public void setAyBottom(float ayBottom) {
        this.ayBottom = ayBottom;
    }

    public float getAyUp() {
        return ayUp;
    }

    public void setAyUp(float ayUp) {
        this.ayUp = ayUp;
    }

    public int getMaxAtackTime() {
        return maxAtackTime;
    }

    public void setMaxAtackTime(int maxAtackTime) {
        this.maxAtackTime = maxAtackTime;
    }

    public int getMaxShootTime() {
        return maxShootTime;
    }

    public void setMaxShootTime(int maxShootTime) {
        this.maxShootTime = maxShootTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getxLeft() {
        return xLeft;
    }

    public void setxLeft(float xLeft) {
        this.xLeft = xLeft;
    }

    public float getxRight() {
        return xRight;
    }

    public void setxRight(float xRight) {
        this.xRight = xRight;
    }

    public float getyBottom() {
        return yBottom;
    }

    public void setyBottom(float yBottom) {
        this.yBottom = yBottom;
    }

    public float getyUp() {
        return yUp;
    }

    public void setyUp(float yUp) {
        this.yUp = yUp;
    }

    public int getExp() {
        return exp;
    }

    public void setExp(int exp) {
        this.exp = exp;
    }

    public int getMaxLife() {
        return maxLife;
    }

    public void setMaxLife(int maxLife) {
        this.maxLife = maxLife;
    }

    public int getMargenDown() {
        return margenDown;
    }

    public void setMargenDown(int margenDown) {
        this.margenDown = margenDown;
    }

    public int getMargenUp() {
        return margenUp;
    }

    public void setMargenUp(int margenUp) {
        this.margenUp = margenUp;
    }

    public Polygon getAtackPoly() {
        return atackPoly;
    }

    public void setAtackPoly(float xLeft, float xRight, float yUp, float yBottom) {
        this.atackPoly = new Polygon(new float[]{xLeft, yUp, xRight, yUp, xRight, yBottom, xLeft, yBottom});
    }

    public boolean isAtack() {
        return atack;
    }

    public void setAtack(boolean Atack) {
        this.atack = Atack;
    }

    public boolean isShoot() {
        return shoot;
    }

    public void setShoot(boolean shoot) {
        this.shoot = shoot;
    }

    public int getLife() {
        return life;
    }

    public void setLife(int life) {
        this.life = life;
    }

    public boolean isLeft() {
        return left;
    }

    public void setLeft(boolean left) {
        this.left = left;
    }

    public boolean isSaltable() {
        return saltable;
    }

    public void setSaltable(boolean saltable) {
        this.saltable = saltable;
    }

    public float getPosX() {
        return posX;
    }

    public float getPosY() {
        return posY;
    }

    public void setPosX(float posX) {
        this.posX = posX;
    }

    public void setPosY(float posY) {
        this.posY = posY;
    }

    public float getVelX() {
        return velX;
    }

    public float getVelY() {
        return velY;
    }

    public void setVelX(float velX) {
        this.velX = velX;
    }

    public void setVelY(float velY) {
        this.velY = velY;
    }

    public Polygon getPoly() {
        return poly;
    }

    public void setPoly(float xLeft, float xRight, float yUp, float yBottom) {
        this.poly = new Polygon(new float[]{xLeft, yUp, xRight, yUp, xRight, yBottom, xLeft, yBottom});
    }

    public ArrayList<Image> getImgs() {
        return imgs;
    }

    public void setImgs(ArrayList<Image> imgs) {
        this.imgs = imgs;
    }

    public Animation getAnimation() {
        return animation;
    }

    public void setAnimation(Animation animation) {
        this.animation = animation;
    }

    public Animation getAnimationDownL() {
        return animationDownL;
    }

    public void setAnimationDownL(Animation animationDownL) {
        this.animationDownL = animationDownL;
    }

    public Animation getAnimationDownR() {
        return animationDownR;
    }

    public void setAnimationDownR(Animation animationDownR) {
        this.animationDownR = animationDownR;
    }

    public Animation getAnimationDownShtL() {
        return animationDownShtL;
    }

    public void setAnimationDownShtL(Animation animationDownShtL) {
        this.animationDownShtL = animationDownShtL;
    }

    public Animation getAnimationDownShtR() {
        return animationDownShtR;
    }

    public void setAnimationDownShtR(Animation animationDownShtR) {
        this.animationDownShtR = animationDownShtR;
    }

    public Animation getAnimationFastL() {
        return animationFastL;
    }

    public void setAnimationFastL(Animation animationFastL) {
        this.animationFastL = animationFastL;
    }

    public Animation getAnimationFastR() {
        return animationFastR;
    }

    public void setAnimationFastR(Animation animationFastR) {
        this.animationFastR = animationFastR;
    }

    public Animation getAnimationParedR() {
        return animationParedR;
    }

    public void setAnimationParedR(Animation animationParedR) {
        this.animationParedR = animationParedR;
    }

    public Animation getAnimationParedL() {
        return animationParedL;
    }

    public void setAnimationParedL(Animation animationParedL) {
        this.animationParedL = animationParedL;
    }

    public Animation getAnimationDieL() {
        return animationDieL;
    }

    public void setAnimationDieL(Animation animationDieL) {
        this.animationDieL = animationDieL;
    }

    public Animation getAnimationDieR() {
        return animationDieR;
    }

    public void setAnimationDieR(Animation animationDieR) {
        this.animationDieR = animationDieR;
    }

    public Animation getAnimationHurtL() {
        return animationHurtL;
    }

    public void setAnimationHurtL(Animation animationHurtL) {
        this.animationHurtL = animationHurtL;
    }

    public Animation getAnimationHurtR() {
        return animationHurtR;
    }

    public void setAnimationHurtR(Animation animationHurtR) {
        this.animationHurtR = animationHurtR;
    }

    public boolean isDown() {
        return down;
    }

    public void setDown(boolean down) {
        this.down = down;
    }

    public boolean isPared() {
        return pared;
    }

    public void setPared(boolean pared) {
        this.pared = pared;
    }

    public boolean isDead() {
        return dead;
    }

    public void setDead(boolean dead) {
        this.dead = dead;
    }

    public boolean isHurt() {
        return hurt;
    }

    public void setHurt(boolean hurt) {
        this.hurt = hurt;
    }

    public boolean isDieAni() {
        return dieAni;
    }

    public void setDieAni(boolean dieAni) {
        this.dieAni = dieAni;
    }

    public void Update(GameContainer gc, int delta, Physics phys) {


        //fisicas
        phys.gravity(delta, this);
        if (velY != 0) {
            phys.distY(delta, this);
        }
        poly.setY(posY + margenUp);
        atackPoly.setY(posY + margenUp);
        if (velX != 0) {
            phys.distX(delta, this);
        }
        poly.setX(posX + margenDown);
        if (left) {
            atackPoly.setX(posX);
        } else {
            atackPoly.setX(posX + 40);
        }
        //end Fisicas



        //Animaciones
        if (!hurt) {
            if (isAtack()) {
                atackTime = atackTime + delta;
                if (atackTime > maxAtackTime) {
                    atackTime = 0;
                    atack = false;
                }
                if (left) {
                    animation = animationAtL;
                } else {
                    animation = animationAtR;
                }
            } else if (isShoot()) {
                shootTime = shootTime + delta;
                if (shootTime > maxShootTime) {
                    shootTime = 0;
                    shoot = false;
                }
                if (left) {
                    if (isDown()) {
                        animation = animationDownShtL;
                    } else {
                        animation = animationShtL;
                    }
                } else {
                    if (isDown()) {
                        animation = animationDownShtR;
                    } else {
                        animation = animationShtR;
                    }
                }
            } else {
                if (velY != 0) {
                    if (left == false) {
                        if (!pared) {
                            animation = animationJumpR;
                        } else {
                            animation = animationParedR;
                        }
                    } else {
                        if (!pared) {
                            animation = animationJumpL;
                        } else {
                            animation = animationParedL;
                        }
                    }
                } else if (velX != 0) {
                    if (left == false) {
                        animation = animationRR;
                    } else {
                        animation = animationRL;
                    }
                } else {
                    if (left == false) {
                        if (isDown()) {
                            animation = animationDownR;
                        } else {
                            animation = animationR;
                        }
                    } else {
                        if (isDown()) {
                            animation = animationDownL;
                        } else {
                            animation = animationL;
                        }
                    }
                }
            }
        } else {
            if (!dieAni) {
                if (hurtTime < 500) {
                    if (!isLeft()) {
                        animation = animationHurtR;
                    } else {
                        animation = animationHurtL;
                    }
                    hurtTime = hurtTime + delta;
                } else {
                    hurtTime = 0;
                    hurt = false;
                }
                if(getLife()<=0){
                    dieAni=true;
                }
            }else{
                if (dieTime < 500) {
                    if (!isLeft()) {
                        animation = animationDieR;
                    } else {
                        animation = animationDieL;
                    }
                    dieTime = dieTime + delta;
                } else {
                    dieTime = 0;
                    dead = true;
                }
            }
        }
        //end animaciones
    }

    public void Render(GameContainer gc, Graphics g, int incX, int incY) {
        g.drawAnimation(animation, posX + incX, posY + incY);
//        g.draw(poly);
//        g.draw(atackPoly);
    }
}
